package com.ruoyi.system.domain.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.ruoyi.common.core.domain.entity.SysDept;
import lombok.Data;

import java.io.Serializable;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Treeselect树结构实体类
 *
 * @author ruoyi
 */
@Data
public class WxTreeSelect implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 节点ID
     */
    private String value;
    /**
     * 节点名称
     */
    private String text;

    /**
     * 子节点
     */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<WxTreeSelect> children;

    public WxTreeSelect(SysDept dept) {
        this.value = dept.getFlag();
        this.text = dept.getDeptShortName();
        if (dept.getChildren() != null) {
            this.children = dept.getChildren().stream().map(WxTreeSelect::new).collect(Collectors.toList());
        }
    }
}
